home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCLIEN.PAK / MAINDOC.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  193 lines

  1. // maindoc.cpp : implementation of the CMainDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14. #include "stdafx.h"
  15. #include "oclient.h"
  16.  
  17. #include "maindoc.h"
  18. #include "rectitem.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. // private clipboard format
  26. CLIPFORMAT CMainDoc::m_cfPrivate = NULL;
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CMainDoc
  30.  
  31. IMPLEMENT_DYNCREATE(CMainDoc, COleLinkingDoc)
  32.  
  33. BEGIN_MESSAGE_MAP(CMainDoc, COleLinkingDoc)
  34.     //{{AFX_MSG_MAP(CMainDoc)
  35.     ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
  36.     ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
  37.     //}}AFX_MSG_MAP
  38.     ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePasteMenu)
  39.     ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, OnUpdatePasteLinkMenu)
  40.     ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, OnUpdateEditLinksMenu)
  41.     ON_COMMAND(ID_OLE_EDIT_LINKS, OnEditLinks)
  42.     ON_UPDATE_COMMAND_UI(ID_OLE_VERB_FIRST, OnUpdateObjectVerbMenu)
  43.     ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CHANGE_ICON, OnUpdateEditChangeIcon)
  44.     ON_COMMAND(ID_OLE_EDIT_CHANGE_ICON, OnEditChangeIcon)
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CMainDoc construction/destruction
  49.  
  50. CMainDoc::CMainDoc() : m_sizeDoc(800,1050) // document size is 8x10.5
  51. {
  52.     EnableCompoundFile();
  53.  
  54.     m_bNeedUpdate = TRUE;
  55.     if (m_cfPrivate == NULL)
  56.         m_cfPrivate = (CLIPFORMAT)
  57. #ifdef _MAC
  58.             ::RegisterClipboardFormat(_T("OCLI"));
  59. #else
  60.             ::RegisterClipboardFormat(_T("MFC OClient Sample"));
  61. #endif // _MAC
  62. }
  63.  
  64. CMainDoc::~CMainDoc()
  65. {
  66. }
  67.  
  68. CSize &CMainDoc::GetDocumentSize()
  69. {
  70.     return m_sizeDoc;
  71. }
  72.  
  73. void CMainDoc::OnShowViews(BOOL bVisible)
  74. {
  75.     COleLinkingDoc::OnShowViews(bVisible);
  76.  
  77.     if (bVisible && m_bNeedUpdate)
  78.     {
  79.         // update embedded links in this document before showing the window
  80.         COleUpdateDialog dlg(this);
  81.         dlg.DoModal();
  82.         m_bNeedUpdate = FALSE;
  83.     }
  84. }
  85.  
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CMainDoc item management
  88.  
  89. CRectItem* CMainDoc::CreateItem()
  90. {
  91.     return new CRectItem(this); // does 'AddItem' automatically
  92. }
  93.  
  94. // safe delete that notifies views
  95. void CMainDoc::DeleteItem(CRectItem* pItem)
  96. {
  97.     ASSERT(pItem->GetDocument() == this);
  98.  
  99.     SetModifiedFlag();
  100.     UpdateAllViews(NULL, 1, pItem); // pItem will be deleted
  101.     pItem->Delete();    // does a 'RemoveItem' & 'delete this' automatically
  102. }
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CMainDoc serialization
  106.  
  107. void CMainDoc::Serialize(CArchive& ar)
  108. {
  109. // NOTE: New easier to use serialization model -- even for OLE objects!
  110.     WORD wMagic = 0x0DAF;
  111.     if (ar.IsStoring())
  112.     {
  113.         if (HasBlankItems() &&
  114.             AfxMessageBox(IDP_SAVEINCOMPLETE, MB_YESNO|MB_ICONQUESTION) != IDYES)
  115.         {
  116.             TRACE0("Aborting save -- incomplete items found!\n");
  117.             AfxThrowArchiveException(CArchiveException::generic);
  118.         }
  119.         ar << wMagic;
  120.     }
  121.     else
  122.     {
  123.         WORD w;
  124.         ar >> w;
  125.  
  126.         if (w != wMagic)
  127.         {
  128.             TRACE0("invalid magic number at start of file\n");
  129.             AfxThrowArchiveException(CArchiveException::generic);
  130.         }
  131.     }
  132.  
  133.     // serialize the rest of the document (OLE items)
  134.     COleLinkingDoc::Serialize(ar);
  135. }
  136.  
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CMainDoc commands
  139.  
  140. void CMainDoc::OnEditClearAll()
  141. {
  142.     // delete all items in the document (also removes sub-storages)
  143.     POSITION pos = GetStartPosition();
  144.     while (pos != NULL)
  145.     {
  146.         CRectItem* pItem = (CRectItem*)GetNextItem(pos);
  147.         ASSERT_KINDOF(CRectItem, pItem);
  148.         pItem->Delete();
  149.     }
  150.  
  151.     // everything is gone now!
  152.     SetModifiedFlag();
  153.     UpdateAllViews(NULL);
  154. }
  155.  
  156.  
  157. void CMainDoc::OnUpdateEditClearAll(CCmdUI* pCmdUI)
  158. {
  159.     // Enable ClearAll if there is anything to clear
  160.     pCmdUI->Enable(GetStartPosition() != NULL);
  161. }
  162.  
  163. void CMainDoc::AdjustItemPosition(CRectItem* pItem)
  164. {
  165.     POSITION pos = GetStartPosition();
  166.     while (pos != NULL)
  167.     {
  168.         CRectItem* pRectItem = (CRectItem*)GetNextItem(pos);
  169.         ASSERT_KINDOF(CRectItem, pItem);
  170.         if (pRectItem != pItem && pRectItem->GetRect() == pItem->GetRect())
  171.         {
  172.             pItem->m_ptPos.x += 10;
  173.             pItem->m_ptPos.y -= 10;
  174.             pos = GetStartPosition();
  175.         }
  176.     }
  177. }
  178.  
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CMainDoc diagnostics
  181.  
  182. #ifdef _DEBUG
  183. void CMainDoc::AssertValid() const
  184. {
  185.     COleLinkingDoc::AssertValid();
  186. }
  187.  
  188. void CMainDoc::Dump(CDumpContext& dc) const
  189. {
  190.     COleLinkingDoc::Dump(dc);
  191. }
  192. #endif //_DEBUG
  193.